package com.venutech.gongan.vo;


import com.venutech.gongan.dto.rpc.common.ApiBusinessCode;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

/**
 * Created by gutianen on 2020/3/25.
 */
@Getter
@Setter
public class ApiResponse<T> implements Serializable {

    private String bizCode;
    private String message;
    private T data;

    private ApiResponse() {
    }

    private ApiResponse(String bizCode, String message, T data) {
        this.bizCode = bizCode;
        this.message = message;
        this.data = data;
    }

    public static ApiResponse<Void> success() {
        return new ApiResponse(ApiBusinessCode.SUCCESS.getCode(), ApiBusinessCode.SUCCESS.getMsg(), (Object)null);
    }

    public static <T> ApiResponse<T> success(T result) {
        return new ApiResponse(ApiBusinessCode.SUCCESS.getCode(), ApiBusinessCode.SUCCESS.getMsg(), result);
    }

    public static <T> ApiResponse<T> error(String code, String msg) {
        return new ApiResponse(code, msg, (Object)null);
    }

    public static <T> ApiResponse<T> success(String code, String msg) {
        return new ApiResponse(code, msg, (Object)null);
    }


    public boolean isSuccess() {
        return ApiBusinessCode.SUCCESS.getCode().equals(this.bizCode);
    }

    public boolean isFail() {
        return !this.isSuccess();
    }

}
